# -*- coding: utf-8 -*-
from odoo import models, api, fields, tools
from odoo.exceptions import UserError
import re


class air_quality(models.Model):

    _name = "datcent.air_quality"
    _description = "空气质量"
    _table = "datcent_air_quality"
    _order = "sequence"
    _inherit =  ['mail.thread', 'mail.activity.mixin', 'image.mixin']

    sequence = fields.Integer(string="排序",translate = 0)
    name = fields.Many2one(string="站点名称",comodel_name = 'setcent.region',translate = 0)
    region_id = fields.Many2one(string="省市县区",comodel_name = 'setcent.region',translate = 0)
    datetime = fields.Datetime(string="年月日",translate = 0)
    aqi_index = fields.Float(string="AQI指数",translate = 0)
    air_quality_level = fields.Selection(string="空气质量级别",selection = [('1', '优'), ('2', '良'), ('3', '轻度污染'), ('4', '中度污染'), ('5', '重度污染'), ('6', '严重污染')],default='1',translate = 0)
    primary_pollutant = fields.Char(string="首要污染物",translate = 0)
    image = fields.Binary(string="相关照片",translate = 0)
    detail_contents = fields.Html(string="详细说明",translate = 0)
    attachment = fields.Many2many(string="相关附件",comodel_name = 'ir.attachment',translate = 0)
    state = fields.Selection(string="状态",selection = [('1', '草稿'), ('2', '提交'), ('3', '审核')],default='1',translate = 0)

    def button1(self):
        if self.state == '1':
            self.write({'state': '2'})
        # 审核
    def button2(self):
        if self.state == '2':
            self.write({'state': '3'})
        # 退回
    def button3(self):
        if self.state == '2':
            self.write({'state': '1'})

        # 反审核
    def button4(self):
        if self.state == '3':
            self.write({'state': '2'})
